package com.xqb.modules.controller.order;

import com.xqb.common.annotation.Log;
import com.xqb.common.core.controller.BaseController;
import com.xqb.common.core.domain.AjaxResult;
import com.xqb.common.core.page.TableDataInfo;
import com.xqb.common.enums.BusinessType;
import com.xqb.common.utils.poi.ExcelUtil;
import com.xqb.modules.domain.po.OrdOrderDetail;
import com.xqb.modules.service.IOrdOrderDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 订单明细Controller
 * 
 * @author xqb
 * @date 2024-10-14
 */
@RestController
@RequestMapping("/order/order_detail")
public class OrdOrderDetailController extends BaseController
{
    @Autowired
    private IOrdOrderDetailService ordOrderDetailService;

    /**
     * 查询订单明细列表
     */
    @PreAuthorize("@ss.hasPermi('order:order_detail:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrdOrderDetail ordOrderDetail)
    {
        startPage();
        List<OrdOrderDetail> list = ordOrderDetailService.selectOrdOrderDetailList(ordOrderDetail);
        return getDataTable(list);
    }

    /**
     * 导出订单明细列表
     */
    @PreAuthorize("@ss.hasPermi('order:order_detail:export')")
    @Log(title = "订单明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrdOrderDetail ordOrderDetail)
    {
        List<OrdOrderDetail> list = ordOrderDetailService.selectOrdOrderDetailList(ordOrderDetail);
        ExcelUtil<OrdOrderDetail> util = new ExcelUtil<OrdOrderDetail>(OrdOrderDetail.class);
        util.exportExcel(response, list, "订单明细数据");
    }

    /**
     * 获取订单明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:order_detail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ordOrderDetailService.selectOrdOrderDetailById(id));
    }

    /**
     * 新增订单明细
     */
    @PreAuthorize("@ss.hasPermi('order:order_detail:add')")
    @Log(title = "订单明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrdOrderDetail ordOrderDetail)
    {
        return toAjax(ordOrderDetailService.insertOrdOrderDetail(ordOrderDetail));
    }

    /**
     * 修改订单明细
     */
    @PreAuthorize("@ss.hasPermi('order:order_detail:edit')")
    @Log(title = "订单明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrdOrderDetail ordOrderDetail)
    {
        return toAjax(ordOrderDetailService.updateOrdOrderDetail(ordOrderDetail));
    }

    /**
     * 删除订单明细
     */
    @PreAuthorize("@ss.hasPermi('order:order_detail:remove')")
    @Log(title = "订单明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ordOrderDetailService.deleteOrdOrderDetailByIds(ids));
    }
}
